package services;

import domain.entities.IrbSop;
import domain.entities.IrbSopDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: vgonzalez
 * Date: 01/11/12
 * Time: 13:34
 * To change this template use File | Settings | File Templates.
 */
@Service
public class IrbSopService implements CRUDService<IrbSop>{

    private IrbSopDAO irbSopDAO;

    public IrbSopService(){
    }

    @Autowired
    public IrbSopService(IrbSopDAO irbSopDAO) {
        this.irbSopDAO = irbSopDAO;
    }

    public IrbSop findById(Integer id){
        return irbSopDAO.findById(id);
    }

    public void save(IrbSop obj){
        this.irbSopDAO.merge(obj);
    }

    public List<IrbSop> findAll() {
        return irbSopDAO.findAll();
    }

    public <V extends Criteria> List<IrbSop> list(V criteria) {
        List<IrbSop> list = irbSopDAO.findAll();
        Iterator<IrbSop> it = list.iterator();
        while(it.hasNext()){
            if(!criteria.isIn(it.next())){
                it.remove();
            }
        }
        return list;
    }
}
